package cn.wuqingna.legendgem.api

import cn.wuqingna.legendgem.cache.PlayerManager
import org.bukkit.OfflinePlayer
import taboolib.platform.compat.PlaceholderExpansion


object PAPI: PlaceholderExpansion {
    override val identifier: String
        get() = "lgem"
    override val autoReload: Boolean
        get() = true

    override fun onPlaceholderRequest(player: OfflinePlayer?, args: String,): String {
        if (player == null) {return "error"}
        val cache = PlayerManager.get(player.uniqueId)
        val args = args.split("_")
        val identifier = args[0] // custom
        val source = args[1] //data
        val type = args[2] // get-int/count/double/flot
        val name = args[3]

        when (type) {
            "get-int" -> { return cache.getCustomData(name).toInt().toString() }
            "get-count" -> { return cache.getCustomData(name).toInt().toString() }
            "get-double" -> { return cache.getCustomData(name).toString() }
            "get-flot" -> { return cache.getCustomData(name).toFloat().toString() }
        }


        PlayerManager.delOffline(player.uniqueId)



        return "error"
    }


}